home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / gdb / foo / readline / funmap.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-10-06  |  6.4 KB  |  218 lines

  1. /* funmap.c -- attach names to functions. */
  2.  
  3. /* Copyright (C) 1988,1989 Free Software Foundation, Inc.
  4.  
  5.    This file is part of GNU Readline, a library for reading lines
  6.    of text with interactive input and history editing.
  7.  
  8.    Readline is free software; you can redistribute it and/or modify it
  9.    under the terms of the GNU General Public License as published by the
  10.    Free Software Foundation; either version 1, or (at your option) any
  11.    later version.
  12.  
  13.    Readline is distributed in the hope that it will be useful, but
  14.    WITHOUT ANY WARRANTY; without even the implied warranty of
  15.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16.    General Public License for more details.
  17.  
  18.    You should have received a copy of the GNU General Public License
  19.    along with Readline; see the file COPYING.  If not, write to the Free
  20.    Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
  21.  
  22. #define STATIC_MALLOC
  23. #ifndef STATIC_MALLOC
  24. extern char *xmalloc (), *xrealloc ();
  25. #else
  26. static char *xmalloc (), *xrealloc ();
  27. #endif
  28.  
  29. #ifndef FILE
  30. #include <stdio.h>
  31. #endif /* FILE */
  32.  
  33. #include "readline.h"
  34.  
  35. FUNMAP **funmap = (FUNMAP **)NULL;
  36. static int funmap_size = 0;
  37.  
  38. static int just_testing_ar_tmp = 0;
  39. static int just_testing_ar_tmp_2 = 5;
  40. int foo_testing_ar;
  41.  
  42. static int funmap_entry = 0;
  43.  
  44. static FUNMAP default_funmap[] = {
  45.   { "beginning-of-line", rl_beg_of_line },
  46.   { "backward-char", rl_backward },
  47.   { "delete-char", rl_delete },
  48.   { "end-of-line", rl_end_of_line },
  49.   { "forward-char", rl_forward },
  50.   { "accept-line", rl_newline },
  51.   { "kill-line", rl_kill_line },
  52.   { "clear-screen", rl_clear_screen },
  53.   { "next-history", rl_get_next_history },
  54.   { "previous-history", rl_get_previous_history },
  55.   { "quoted-insert", rl_quoted_insert },
  56.   { "reverse-search-history", rl_reverse_search_history },
  57.   { "forward-search-history", rl_forward_search_history },
  58.   { "transpose-chars", rl_transpose_chars },
  59.   { "unix-line-discard", rl_unix_line_discard },
  60.   { "unix-word-rubout", rl_unix_word_rubout },
  61.   { "yank", rl_yank },
  62.   { "yank-pop", rl_yank_pop },
  63.   { "yank-nth-arg", rl_yank_nth_arg },
  64.   { "backward-delete-char", rl_rubout },
  65.   { "backward-word", rl_backward_word },
  66.   { "kill-word", rl_kill_word },
  67.   { "forward-word", rl_forward_word },
  68.   { "tab-insert", rl_tab_insert },
  69.   { "backward-kill-word", rl_backward_kill_word },
  70.   { "backward-kill-line", rl_backward_kill_line },
  71.   { "transpose-words", rl_transpose_words },
  72.   { "digit-argument", rl_digit_argument },
  73.   { "complete", rl_complete },
  74.   { "possible-completions", rl_possible_completions },
  75.   { "do-lowercase-version", rl_do_lowercase_version },
  76.   { "digit-argument", rl_digit_argument },
  77.   { "universal-argument", rl_universal_argument },
  78.   { "abort", rl_abort },
  79.   { "undo", rl_undo_command },
  80.   { "upcase-word", rl_upcase_word },
  81.   { "downcase-word", rl_downcase_word },
  82.   { "capitalize-word", rl_capitalize_word },
  83.   { "revert-line", rl_revert_line },
  84.   { "beginning-of-history", rl_beginning_of_history },
  85.   { "end-of-history", rl_end_of_history },
  86.   { "self-insert", rl_insert },
  87.   { "start-kbd-macro", rl_start_kbd_macro },
  88.   { "end-kbd-macro", rl_end_kbd_macro },
  89.   { "re-read-init-file", rl_re_read_init_file },
  90. #ifdef VI_MODE
  91.   { "vi-movement-mode", rl_vi_movement_mode },
  92.   { "vi-insertion-mode", rl_vi_insertion_mode },
  93.   { "vi-arg-digit", rl_vi_arg_digit },
  94.   { "vi-prev-word", rl_vi_prev_word },
  95.   { "vi-next-word", rl_vi_next_word },
  96.   { "vi-char-search", rl_vi_char_search },
  97.   { "vi-editing-mode", rl_vi_editing_mode },
  98.   { "vi-eof-maybe", rl_vi_eof_maybe },
  99.   { "vi-append-mode", rl_vi_append_mode },
  100.   { "vi-put", rl_vi_put },
  101.   { "vi-append-eol", rl_vi_append_eol },
  102.   { "vi-insert-beg", rl_vi_insert_beg },
  103.   { "vi-delete", rl_vi_delete },
  104.   { "vi-comment", rl_vi_comment },
  105.   { "vi-first-print", rl_vi_first_print },
  106.   { "vi-fword", rl_vi_fword },
  107.   { "vi-fWord", rl_vi_fWord },
  108.   { "vi-bword", rl_vi_bword },
  109.   { "vi-bWord", rl_vi_bWord },
  110.   { "vi-eword", rl_vi_eword },
  111.   { "vi-eWord", rl_vi_eWord },
  112.   { "vi-end-word", rl_vi_end_word },
  113.   { "vi-change-case", rl_vi_change_case },
  114.   { "vi-match", rl_vi_match },
  115.   { "vi-bracktype", rl_vi_bracktype },
  116.   { "vi-change-char", rl_vi_change_char },
  117.   { "vi-yank-arg", rl_vi_yank_arg },
  118.   { "vi-search", rl_vi_search },
  119.   { "vi-search-again", rl_vi_search_again },
  120.   { "vi-dosearch", rl_vi_dosearch },
  121.   { "vi-subst", rl_vi_subst },
  122.   { "vi-overstrike", rl_vi_overstrike },
  123.   { "vi-overstrike-delete", rl_vi_overstrike_delete },
  124.   { "vi-replace, ", rl_vi_replace },
  125.   { "vi-column", rl_vi_column },
  126.   { "vi-delete-to", rl_vi_delete_to },
  127.   { "vi-change-to", rl_vi_change_to },
  128.   { "vi-yank-to", rl_vi_yank_to },
  129.   { "vi-complete", rl_vi_complete },
  130. #endif /* VI_MODE */
  131.  
  132.  {(char *)NULL, (Function *)NULL }
  133. };
  134.  
  135. rl_add_funmap_entry (name, function)
  136.      char *name;
  137.      Function *function;
  138. {
  139.   if (funmap_entry + 2 >= funmap_size)
  140.     if (!funmap)
  141.       funmap = (FUNMAP **)xmalloc ((funmap_size = 80) * sizeof (FUNMAP *));
  142.     else
  143.       funmap =
  144.     (FUNMAP **)xrealloc (funmap, (funmap_size += 80) * sizeof (FUNMAP *));
  145.   
  146.   funmap[funmap_entry] = (FUNMAP *)xmalloc (sizeof (FUNMAP));
  147.   funmap[funmap_entry]->name = name;
  148.   funmap[funmap_entry]->function = function;
  149.  
  150.   funmap[++funmap_entry] = (FUNMAP *)NULL;
  151. }
  152.  
  153. static int funmap_initialized = 0;
  154.  
  155. /* Make the funmap contain all of the default entries. */
  156. rl_initialize_funmap ()
  157. {
  158.   register int i;
  159.  
  160.   if (funmap_initialized)
  161.     return;
  162.  
  163.   for (i = 0; default_funmap[i].name; i++)
  164.     rl_add_funmap_entry (default_funmap[i].name, default_funmap[i].function);
  165.  
  166.   funmap_initialized = 1;
  167. }
  168.  
  169. /* Things that mean `Control'. */
  170. char *possible_control_prefixes[] = {
  171.   "Control-", "C-", "CTRL-", (char *)NULL
  172. };
  173.  
  174. char *possible_meta_prefixes[] = {
  175.   "Meta", "M-", (char *)NULL
  176. };
  177.  
  178. #ifdef STATIC_MALLOC
  179.  
  180. /* **************************************************************** */
  181. /*                                    */
  182. /*            xmalloc and xrealloc ()                     */
  183. /*                                    */
  184. /* **************************************************************** */
  185.  
  186. static char *
  187. xmalloc (bytes)
  188.      int bytes;
  189. {
  190.   static memory_error_and_abort ();
  191.   char *temp = (char *)malloc (bytes);
  192.  
  193.   if (!temp)
  194.     memory_error_and_abort ();
  195.   return (temp);
  196. }
  197.  
  198. static char *
  199. xrealloc (pointer, bytes)
  200.      char *pointer;
  201.      int bytes;
  202. {
  203.   static memory_error_and_abort ();
  204.   char *temp = (char *)realloc (pointer, bytes);
  205.  
  206.   if (!temp)
  207.     memory_error_and_abort ();
  208.   return (temp);
  209. }
  210.  
  211. static
  212. memory_error_and_abort ()
  213. {
  214.   fprintf (stderr, "history: Out of virtual memory!\n");
  215.   abort ();
  216. }
  217. #endif /* STATIC_MALLOC */
  218.